package org.ros.android.android_tutorial_image_transport;

import org.ros.concurrent.CancellableLoop;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.topic.Publisher;

import static java.lang.Thread.sleep;

/**
 * Created by corvin on 17-8-7.
 */

public class ProjectorControl extends AbstractNodeMain
{
    private String topic_name;

    public ProjectorControl() {
        this.topic_name = "/projector_cmd";
    }

    public GraphName getDefaultNodeName() {
        return GraphName.of("ProjectorControl");
    }

    public void onStart(ConnectedNode connectedNode)
    {
        final Publisher<std_msgs.Int32> publisher = connectedNode.newPublisher(this.topic_name, "std_msgs/Int32");
        connectedNode.executeCancellableLoop(new CancellableLoop()
        {
            protected void setup() {            }

            protected void loop() throws InterruptedException
            {
                if(MainActivity.projectorCMDFlag )
                {
                    std_msgs.Int32 cmd = publisher.newMessage();
                    cmd.setData(MainActivity.projectorCMD);
                    publisher.publish(cmd);
                }
                MainActivity.projectorCMDFlag = false;
                sleep( 100 );
            }
        });
    }
}